<template>
  <BasicModal width="1000px" @register="register" @ok="handleSubmit">
    <BasicTable @register="registerTable" :searchInfo="searchInfo" >
      <template #toolbar>
      </template>
      <template #action="{ record }">
      </template>
    </BasicTable>
  </BasicModal>
</template>
<script lang="ts">
  import { defineComponent, reactive } from 'vue';

  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { getcodegenByconfig, codegenconapi } from '../../system-api';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { useModal } from '/@/components/Modal';


  import { columns, searchFormSchema } from './dictdata.data';
  import { useGo } from '/@/hooks/web/usePage';
  import { useMessage } from '/@/hooks/web/useMessage';

  export default defineComponent({
    name: 'AccountManagement',
    components: { BasicTable, BasicModal },
    setup() {
      const { createMessage } = useMessage();
      const go = useGo();
      const [registerModal, { openModal }] = useModal();
      const searchInfo = reactive<Recordable>({});
      let typeId;
      const [registerTable, { reload, updateTableDataRecord, getDataSource }] = useTable({
        title: '列表内容',
        api: getcodegenByconfig,
        beforeFetch(params) {
          params = typeId;
          return params;
        },
        rowKey: 'id',
        columns,
        fetchSetting: {
          pageField: 'page',
          sizeField: 'pageSize',
          listField: 'rows',
          totalField: 'totalRows',
        },
        bordered: true,
        handleSearchInfoFn(info) {
          return info;
        },
      });
      const [register, { closeModal }] = useModalInner((data) => {
        typeId = data.record.id;
        reload();
        console.log(data.record);
      });

      function handleSelect(deptId = '') {
        searchInfo.deptId = deptId;
        console.log(deptId);
        reload();
      }

      async function handleSubmit() {
        try {
          let values = getDataSource();
          let ret: any;
          ret = (await codegenconapi.sysCodeGenerateConfigEditPost(values)).data;
          if (ret != null) {
            if (ret.code == 204) {
              closeModal();
              createMessage.success(ret.message);
            } else {
              createMessage.warning(ret.message + ret.message[0].messages);
            }
          } else {
            createMessage.error('未知错误');
          }
          console.log(values);
        } finally {
        }
      }
      function handleView(record: Recordable) {
        go('/system/account_detail/' + record.id);
      }

      return {
        register,
        registerTable,
        registerModal,
        handleSelect,
        handleView,
        handleSubmit,
        searchInfo,
      };
    },
  });
</script>

